package xin.nick.minicat;

/**
 * @author Nick
 * @date 2021/6/20
 * @description
 */
public class HttpProtocolUtil {

    /**
     * 正常返回请求头
     * @param contentLength
     * @return
     */
    public static String getHttpHeader200(long contentLength) {
        return new StringBuilder("HTTP/1.1 200 OK \n")
                .append("Content-Type: text/html \n")
                .append("Content-Length: " + contentLength + "\n")
                .append("\r\n").toString();
    }

    /**
     * 404请求头
     * @return
     */
    public static String getHttpHeader404() {
        String str404 = "404";
        return new StringBuilder("HTTP/1.1 404 NOT Found \n")
                .append("Content-Type: text/html \n")
                .append("Content-Length: " + str404.getBytes().length + "\n")
                .append("\r\n")
                .append(str404).toString();
    }

}
